package top.itlir.edc.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;

import top.itlir.edc.dao.PromotionRepository;
import top.itlir.edc.domain.PageBean;
import top.itlir.edc.domain.Promotion;
import top.itlir.edc.service.IPromotionRemoteService;

public class PromotionServiceRemoteImpl implements IPromotionRemoteService {

	@Autowired
	private PromotionRepository promotionRepository;

	@Override
	public PageBean<Promotion> pageQuery(Integer page, Integer pageSize) {
		
		Pageable pageable = new PageRequest(page - 1, pageSize);
		Page<Promotion> pagePro = promotionRepository.findAll(pageable);
		
		//将查询结果放到PageBean中
		PageBean<Promotion> pageBean = new PageBean<Promotion>();
		pageBean.setTotalCount(pagePro.getTotalElements());//总条数
		pageBean.setPageData(pagePro.getContent());//当前页数据集合
		return pageBean;
	}

	@Override
	public Promotion promotionById(Integer id) {
		return promotionRepository.findOne(id);
	}

}
